package com.zjsru.plan2023.oneday.oneDay202303;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: CookLee
 * @Date: 2023/4/14
 * <p>
 * 驼峰式匹配 输入：queries = ["FooBar","FooBarTest","FootBall","FrameBuffer","ForceFeedBack"], pattern = "FB"
 * 输出：[true,false,true,true,false] 示例： "FooBar" 可以这样生成："F" + "oo" + "B" + "ar"。 "FootBall" 可以这样生成："F" + "oot" + "B" +
 * "all". "FrameBuffer" 可以这样生成："F" + "rame" + "B" + "uffer".
 * <p>
 * 输入：queries = ["FooBar","FooBarTest","FootBall","FrameBuffer","ForceFeedBack"], pattern = "FoBa"
 * 输出：[true,false,true,false,false] 解释： "FooBar" 可以这样生成："Fo" + "o" + "Ba" + "r". "FootBall" 可以这样生成："Fo" + "ot" + "Ba" +
 * "ll".
 */
public class CamelMatch {
    
    public List<Boolean> camelMatch(String[] queries, String pattern) {
        List<Boolean> res = new ArrayList<>();
        int length = queries.length;
        for (int i = 0; i < length; i++) {
            int p = 0;
            boolean flag = true;
            for (int j = 0; j < queries[i].length(); j++) {
                char c = queries[i].charAt(j);
                if (p < pattern.length() && pattern.charAt(p) == c) {
                    p++;
                } else if (Character.isUpperCase(c)) {
                    //考虑 c 是否是一个大写字母。如果是，则匹配失败；
                    flag = false;
                    break;
                }
            }
            //表示 pattern 中还有字符未被匹配，
            if (p < pattern.length()) {
                flag = false;
            }
            res.add(flag);
        }
        return res;
    }
    
    public static void main(String[] args) {
        CamelMatch camelMatch = new CamelMatch();
        String[] queries = new String[] {"FooBar", "FooBarTest", "FootBall", "FrameBuffer", "ForceFeedBack"};
        String pattern = "FB";
        System.out.println(camelMatch.camelMatch(queries, pattern));
    }
}
